<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<?php
require './confg.php';

$result = mysqli_query($con, "SELECT password FROM members where username='$_COOKIE[username]'") or die(mysqli_error($con));
$rowdata1 = mysqli_fetch_array($result);

if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
    if ($_COOKIE['password'] != $rowdata1['password']) {
        header('Location: login.html');
    }
} else {
    header('Location: login.html');
}

function createThumbi( $pathToImages, $pathToThumbs, $thumbWidth ) 
{
  if(!is_dir($pathToThumbs))
     mkdir($pathToThumbs, 744);
 else
    chmod($pathToThumbs, 744);
$dir = opendir( $pathToImages );
while (false !== ($fname = readdir( $dir ))) {
    $info = pathinfo($pathToImages . $fname);
    if ( strtolower($info['extension']) == 'jpg' ) 
    {
      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      $width = imagesx( $img );
      $height = imagesy( $img );
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
  }else if( strtolower($info['extension']) == 'png'){
   $img = imagecreatefrompng( "{$pathToImages}{$fname}" );
   $width = imagesx( $img );
   $height = imagesy( $img );
   $new_width = $thumbWidth;
   $new_height = floor( $height * ( $thumbWidth / $width ) );
   $tmp_img = imagecreatetruecolor( $new_width, $new_height );
   imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
   imagepng( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
closedir( $dir );
}
createThumbi("./images/backbar/","./images/backbar/thumb/",300);
createThumbi("./images/banner/","./images/banner/thumb/",300);
createThumbi("./images/body/","./images/body/thumb/",300);
createThumbi("./images/byline/","./images/byline/thumb/",300);
createThumbi("./images/footer/","./images/footer/thumb/",300);
createThumbi("./images/innerbody/","./images/innerbody/thumb/",300);

function showthumbs($folder) {
    if ($handle = opendir('./images/' . $folder)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != ".." && $entry != "thumb") {
                ?>
                <!-- <div class="imgtumb">
                     <img value="backbar" class="imgtumb" onclick="<?php echo 'onClick(this,' . $folder . ')'; ?>" id="<?php echo "$entry"; ?>" src="<?php echo "./images/" . $folder . '/' . $entry; ?>">
                 </div>-->
                <a data-gallery="gallery" title="<?php echo "$entry"; ?>">
                    <img class="st44" value="<?php echo $folder; ?>" onclick="<?php echo 'onClick(this,' . $folder . ')'; ?>" id="<?php echo "$entry"; ?>" src="<?php echo "./images/" . $folder . '/thumb/' . $entry; ?>">
                </a>
                <?php
            }
        }
        closedir($handle);
    }
}
?>
<html>
    <head>
        <script type="text/javascript">
            function onClick(obj, fldr) {
                fldr.value = obj.id;
                var elements = document.getElementsByClassName('st44');
                for (var i = 0; i < elements.length; i++) {
                    if (elements[i].getAttribute('value') == fldr.id) {
                        document.getElementById(elements[i].id).style.cssText = 'box-shadow: rgb(0, 0, 0) 0px 0px 10px;border-radius: 4px;';
                    }
                }
                document.getElementById(obj.id).style.cssText = 'box-shadow: 0px 0px 23px rgb(171, 211, 176);border-radius: 4px;border: groove;';
            }


        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title><?php echo $rowdata['pagetitle']; ?></title>
        <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="./bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="./bootstrap/css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="./bootstrap/css/abhi.css">
        <link rel="stylesheet" media="screen" type="text/css" href="./css/colorpicker.css" />

        <style type="text/css">
            body,td,th {
                font-family: Ubuntu, Tahoma, sans-serif;
                color: rgb(255,255,255);
            }
            body {
                background-color: #000;
            }
            .nav  a{
                text-shadow: 0 0 !important;
            }

        </style>
        <script src="./js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="./farbtastic.js"></script>
        <link rel="stylesheet" href="farbtastic.css" type="text/css" />
        <script language='JavaScript' type='text/javascript' src='./TDE_CMS/cmsloader.js'></script>
    </head>
    <body style="background-image: url('<?php echo $rowdata['backbar']; ?>');background-color:rgb(170, 170, 170)">
        <div class="container" style="max-width: 1000px">

            <div class="row-fluid">

                <!--Modded-->
                <div class="span12" style="height: 47px;">

                    <?php
                    include './menunew.php';
                    ?>

                </div>
            </div>
            <div class="row-fluid " style="color: white">
                <div class="span12" >
                    <a href="changeuser.php" class="btn btn-info">Manage Users</a>

                    <a href="chklogin.php?logout=true" class="btn btn-inverse">Logout</a>

                    <span class="btn btn-primary disabled pull-right"><?php echo "welcome back, " . $_COOKIE['username']; ?></span>


                </div>
            </div>

            <div class="row-fluid body" style="margin-top: 5px; background: rgb(126, 126, 126);box-shadow: inset 0px 0px 22px rgb(0, 0, 0);border-radius: 4px;">

                <div class="span10 offset1">
                    <form class="form-horizontal" method="POST" action="update.php">



                        <div class="control-group">
                            <label class="control-label" for="txtOwner">Owner</label>
                            <div class="controls">
                                <input required=""  type="text" name="owner" value="<?php echo $_COOKIE['username']; ?>"></input>
                                    <!--<select>
                                <?php
                                //  $results = mysqli_query($con,"SELECT distinct owner FROM graphics") or die(mysqli_error($con));
                                //  while($rowdatas = mysqli_fetch_array($results))
                                //  {
                                //      echo '<option>'.$rowdatas['owner'].'</option>';
                                // }
                                // 
                                ?>
                                </select>-->
                            </div>

                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtPageTitle">Page Title</label>
                            <div class="controls">
                                <input  required="" type="text" id="pagetitle" name="pagetitle" data-provide="typeahead">


                            </div>

                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtMenuColor">Menu Color</label>
                            <div class="controls">
                                <input type="text" id="color" name="menucolor" value="#fafafa" />

                                <div id="colorpicker"></div>

                            </div>

                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtMenuBorder">Menu Border Color</label>
                            <div class="controls">

                                <input type="text" id="color1" name="menuborder" value="#e5e5e5" />

                                <div id="colorpicker1"></div>
                            </div>

                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtMenuText">Menu Text Color</label>
                            <div class="controls">

                                <input type="text" id="color2" name="menutext" value="#333" />

                                <div id="colorpicker2"></div>
                            </div>

                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtBackBar">&nbsp;</label>

                            <div class="controls " >
                                <input value="Sync Images" id="refreshimags" type="button">
                                




                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtBackBar">Back Bar</label>

                            <div class="controls imglist" >
                                <input  name="backbar" id="backbar" type="text" value="">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('backbar'); ?>
                                </div>



                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtBanner">Banner</label>
                            <div class="controls  imglist">
                                <input required="" name="banner" type="text" id="banner" data-provide="typeahead">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('banner'); ?>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtBody">Body</label>
                            <div class="controls  imglist">
                                <input  name="body" type="text" id="body" data-provide="typeahead">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('body'); ?>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="inputEmail">Byline</label>
                            <div class="controls  imglist">
                                <input  name="byline" type="text" id="byline" data-provide="typeahead">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('byline'); ?>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="inputEmail">Footer</label>
                            <div class="controls  imglist">
                                <input  name="footer" type="text" id="footer" data-provide="typeahead">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('footer'); ?>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="inputEmail">Inner Body</label>
                            <div class="controls  imglist">
                                <input  name="innerbody" type="text" id="innerbody" data-provide="typeahead">
                                <div id="gallery" data-toggle="modal-gallery" data-target="#modal-gallery">
                                    <?php showthumbs('innerbody'); ?>
                                </div>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtContBdyLft">Content Body Left </label>
                            <div class="controls">
                                <input  name="contbdylft" value="BodyLeft" type="text" data-provide="typeahead">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtContBdyRight">Content Body Right </label>
                            <div class="controls">
                                <input  name="contbdyright" value="BodyRight" type="text"   data-provide="typeahead">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtContBdyLower">Content Body Lower </label>
                            <div class="controls">
                                <input  name="contbdylower" value="BodyLower" type="text"  data-provide="typeahead">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="txtContFooter">Content Footer </label>
                            <div class="controls">
                                <input  name="contfooter" value="Footer" type="text"  data-provide="typeahead">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="ContByLine">Content Byline </label>
                            <div class="controls">
                                <input  name="contbyline" value="Byline" type="text" data-provide="typeahead">
                            </div>
                        </div>

                        <div class="control-group">
                            <div class="controls">
                                <button  type="submit" class="btn btn-block btn-warning">Update</button>
                            </div>
                        </div>
                    </form>

                </div>

            </div>


        </div>
        <br>
        <br>
    </body>
    <script type="text/javascript" src="./bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript">
        $(".collapse").collapse();
        $('.typeahead').typeahead();
        $(document).ready(function() {
            $('#colorpicker').farbtastic('#color');
            $('#colorpicker1').farbtastic('#color1');
            $('#colorpicker2').farbtastic('#color2');
            $('#color').val(<?php echo '"' . $mnuColor . '"'; ?>); //Menu color
            $('#color1').val(<?php echo '"' . $mnuBorderColor . '"'; ?>); //Menu Border color
            $('#color2').val(<?php echo '"' . $mnuTextColor . '"'; ?>); //Menu Text color
            $('#colorpicker').mousemove(function() {
                $('.navbar-inner').css('background', $('#color').val());
            });
            $('#colorpicker1').mousemove(function() {
                $('.navbar-inner').css('border-color', $('#color1').val());
                $('.nav .active a').css('background', $('#color1').val());
            });
            $('#colorpicker2').mousemove(function() {
                $('.nav  a').css('color', $('#color2').val());
                //                $('.nav  a').css('background',$('#color2').val());
            });
        });
        $('#refreshimags').click(function() {
            $("body").css({"opacity": "0.2"});
            alert('Please Wait, The page will reload after Sync.');
            $.post("/gthumb.php", function(data) {
                location.reload();
            });
        }
        );

    </script>
</html>
